package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.LabProjectConstruction;
import com.ruoyi.system.service.ILabProjectConstructionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验室建设项目Controller
 * 
 * @author jun.wang
 * @date 2022-04-13
 */
@RestController
@RequestMapping("/system/construction")
public class LabProjectConstructionController extends BaseController
{
    @Autowired
    private ILabProjectConstructionService labProjectConstructionService;

    /**
     * 查询实验室建设项目列表
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:list')")
    @GetMapping("/list")
    public TableDataInfo list(LabProjectConstruction labProjectConstruction)
    {
        startPage();
        List<LabProjectConstruction> list = labProjectConstructionService.selectLabProjectConstructionList(labProjectConstruction);
        return getDataTable(list);
    }

    /**
     * 导出实验室建设项目列表
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:export')")
    @Log(title = "实验室建设项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LabProjectConstruction labProjectConstruction)
    {
        List<LabProjectConstruction> list = labProjectConstructionService.selectLabProjectConstructionList(labProjectConstruction);
        ExcelUtil<LabProjectConstruction> util = new ExcelUtil<LabProjectConstruction>(LabProjectConstruction.class);
        return util.exportExcel(list, "construction");
    }

    /**
     * 获取实验室建设项目详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:query')")
    @GetMapping(value = "/{instanceId}")
    public AjaxResult getInfo(@PathVariable("instanceId") Long instanceId)
    {
        return AjaxResult.success(labProjectConstructionService.selectLabProjectConstructionById(instanceId));
    }

    /**
     * 新增实验室建设项目
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:add')")
    @Log(title = "实验室建设项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LabProjectConstruction labProjectConstruction)
    {
        return toAjax(labProjectConstructionService.insertLabProjectConstruction(labProjectConstruction));
    }

    /**
     * 修改实验室建设项目
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:edit')")
    @Log(title = "实验室建设项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LabProjectConstruction labProjectConstruction)
    {
        return toAjax(labProjectConstructionService.updateLabProjectConstruction(labProjectConstruction));
    }

    /**
     * 删除实验室建设项目
     */
    // @PreAuthorize("@ss.hasPermi('system:construction:remove')")
    @Log(title = "实验室建设项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instanceIds}")
    public AjaxResult remove(@PathVariable Long[] instanceIds)
    {
        return toAjax(labProjectConstructionService.deleteLabProjectConstructionByIds(instanceIds));
    }
}
